<%@page import="com.lyf.util.DateUtil"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@include file="../include/base.jsp" %>
<!DOCTYPE HTML>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">	
	<title>CRM-contact-main</title>
	<meta charset="UTF-8">
	<%@ include file="../include/head.jsp" %>
	<style type="text/css">
		.dashboard .content a {
			color: #333
		}
		.dashboard a:hover {
			color: #0084B4;
		}
		td.date span {
			color: #999;
		}
		td.date span.label {
			color: #fff;
		}
		.dashboard span.author {
			color: #999;
		}
	</style>
</head>

<body class="crm">
	
<jsp:include page="../include/top.jsp">
	<jsp:param value="main" name="tag"/>
</jsp:include>


<div class="container-fluid">
	<div class="row-fluid">
	<div class="span8">
		

	<div class="well screen">
	<div class="page-header header">
						
						
	<div class="right-links"> 显示
	     <select id="user" name="user">
	        <option>所有同事</option>
	        <optgroup label="同事">
	        <c:forEach items="${userList }" var="user">
	        	<option value="u-${user.id }">${user.username }</option>
			</c:forEach>
			</optgroup>
	     </select> 的
		<script type="text/javascript" charset="utf-8">
			$("#user").live('change', function() {
				$('body').addClass('loading');
				$.get('/dashboard?filter=on&amp;page=1&amp;type=&amp;user=u-5888', {user: this.value}, function(data) {
					$('#main').html(data);
					$('body').removeClass('loading');
				}, 'html');
			});
		</script>
    
	    <select id="type" name="type"><option value="" selected="selected">所有动态</option>
			<option value="task">任务动态</option>
			<option value="chance">机会动态</option>
			<option value="note">事件动态</option>
			<option value="email">邮件动态</option>
		</select>
		<script type="text/javascript" charset="utf-8">
			$('#type').change(function() {
				$('body').addClass('loading');
				$.get('/dashboard?filter=on&amp;page=1&amp;type=&amp;user=u-5888', {type: this.value}, function(data) {
					$('#main').html(data);
					$('body').removeClass('loading');
				}, 'html');
			});
		</script>
	 </div> 最新动态

	 </div>
		<div class="live_search_spinner" behavior="spinner" id="parties_loading">
		  <div class="liner">
		    <h3>处理中...</h3>
		    <img src="${basePath }/img/indicator.gif" alt="WorkXP">
		  </div>
		</div>
		<div class="main" id="main">	
			<table class="table crm-table dashboard">
				<tbody>
				<c:if test="${fn:length(messageList) != 0 }">
					<c:forEach items="${messageList}" var="m">
						<c:set var="time" value="${m.createtime }"></c:set>
						<c:set var="content" value="${m.content }"></c:set>
						<%
							String time = (String)pageContext.getAttribute("time");
							time = DateUtil.getAskedTime(time);
							pageContext.setAttribute("time",time);
							
							String content = (String)pageContext.getAttribute("content");
							content = content.replaceAll("#time#",time);
							pageContext.setAttribute("content",content);
						%>
						${content }
					</c:forEach>
				</c:if>
				<c:if test="${fn:length(messageList) == 0 }">
					There is no latest message...
				</c:if>
				</tbody>
			</table>
	
		</div>
	</div>	

		
	</div>
	<div class="span4 sidebar">
				
		<div id="tasks_div" class="well"><div class="title">
		<span><a data-toggle="modal" href="${basePath }/dashboard#taskModal" data-backdrop="static">添加任务</a></span>
				您的日程安排
			</div>
			<div id="upcoming_tasks">
			<div id="screen_body">
				<c:if test="${fn:length(pastList) != 0 }">
					<legend>已过期</legend>
					<c:forEach items="${pastList }" var="p">
					<div id="task_${p.id }" class="task checkbox">
						<span class="task_hover">
							<div class="task_actions">
								<a href="${basePath }/task/del?id=${p.id}" id="${p.id }" class="icon icon-trash" data-confirm="您确定要删除这个任务吗？" data-method="delete" data-remote="true" rel="nofollow" title="删除这个任务"></a>
								<a href="${basePath }/task/tasktype" class="edit" data-remote="true">编辑</a>
							</div>
							
							<input data-confirm="您确定要完成分配给 shy935397008 的任务吗？" id="task_done_${p.id }" name="task_done" onclick="done_task(this)" type="checkbox" value="${p.id }" alt="${p.user.username }">
							<c:if test="${p.tasktype.type != null }">
								<span style="background:#${p.tasktype.color};" class="label">${p.tasktype.type }</span>
							</c:if>
							${p.user.username }:${p.title }
						</span>
					</div>
					</c:forEach>
				</c:if>
				<c:if test="${fn:length(todayList) != 0 }">
					<legend>今日任务</legend>
					<c:forEach items="${todayList }" var="td">
					<div id="task_${td.id }" class="task checkbox">
						<span class="task_hover">
							<div class="task_actions">
								<a href="${basePath }/task/del?id=${td.id}" id="${td.id }" class="icon icon-trash" data-confirm="您确定要删除这个任务吗？" data-method="delete" data-remote="true" rel="nofollow" title="删除这个任务"></a>
								<a href="${basePath }/task/tasktype" class="edit" data-remote="true">编辑</a>
							</div>
							
							<input data-confirm="您确定要完成分配给 shy935397008 的任务吗？" id="task_done_${td.id }" name="task_done" onclick="done_task(this)" type="checkbox" value="${td.id }" alt="${td.user.username }">
							<c:if test="${td.tasktype.type != null }">
								<span style="background:#${td.tasktype.color};" class="label">${td.tasktype.type }</span>
							</c:if>
							${td.user.username }:${td.title }
						</span>
					</div>
					</c:forEach>
				</c:if>
				<c:if test="${fn:length(tomorrowList) != 0 }">
					<legend>明日任务</legend>
					<c:forEach items="${tomorrowList }" var="t">
					<div id="task_${t.id }" class="task checkbox">
						<span class="task_hover">
							<div class="task_actions">
								<a href="${basePath }/task/del?id=${t.id}" id=${t.id } class="icon icon-trash" data-confirm="您确定要删除这个任务吗？" data-method="delete" data-remote="true" rel="nofollow" title="删除这个任务"></a>
								<a href="${basePath }/task/tasktype" class="edit" data-remote="true">编辑</a>
							</div>
							
							<input data-confirm="您确定要完成分配给 shy935397008 的任务吗？" id="task_done_${t.id }" name="task_done" onclick="done_task(this)" type="checkbox" value="${t.id }" alt="${t.user.username }">
							<c:if test="${t.tasktype.type != null }">
								<span style="background:#${t.tasktype.color};" class="label">${t.tasktype.type }</span>
							</c:if>
							${t.user.username }:${t.title }
						</span>
					</div>
					</c:forEach>
				</c:if>
				<c:if test="${fn:length(laterList) != 0 }">
					<legend>明日以后任务</legend>
					<c:forEach items="${laterList }" var="la">
					<div id="task_${la.id }" class="task checkbox">
						<span class="task_hover">
							<div class="task_actions">
								<a href="${basePath }/task/del?id=${la.id}" id=${la.id } class="icon icon-trash" data-confirm="您确定要删除这个任务吗？" data-method="delete" data-remote="true" rel="nofollow" title="删除这个任务"></a>
								<a href="${basePath }/task/edittask" class="edit" data-remote="true">编辑</a>
							</div>
							
							<input data-confirm="您确定要完成分配给 shy935397008 的任务吗？" id="task_done_${la.id }" name="task_done" onclick="done_task(this)" type="checkbox" value="${la.id }" alt="${la.user.username }">
							<c:if test="${t.tasktype.type != null }">
								<span style="background:#${t.tasktype.color};" class="label">${la.tasktype.type }</span>
							</c:if>
							${la.user.username }:${la.title }
						</span>
					</div>
					</c:forEach>
				</c:if>
				<c:if test="${fn:length(taskList) == 0 }" var="task">
					<div id="upcoming_tasks">
						<div class="alert alert-info"> 没有待办任务，或者已经完成了所有任务！ </div>
					</div>
				</c:if>
			
			</div>
			
			</div>
		</div>
		<script type="text/javascript">
			//删除：set view为false
			$("a[data-method='delete']").click(function(){
				var id = $(this).attr("id");
				$("#task_"+id).fadeOut('slow',function(obj){
					$(obj).remove();
				});
			});
			
			//标注为完成
			function done_task(obj){
				var id = $(obj).attr("value");
				var name = $(obj).attr("alt");
				if(confirm("您确定要完成分配给 "+name+" 的任务吗？")){
					$.post("${basePath}/task/done",{"id":id},function(){
						$("#task_"+id).fadeOut('slow',function(obj){
							$(obj).remove();
						});
					});
				}else{
					$(obj).attr("checked",false);
				}
			}
		</script>
		<script type="text/javascript" charset="utf-8">
			$(document).ready(function() {
				$('span.task_hover').hover(function() {
					$(this).children().first().show();
				}, function() {
					$(this).children().first().hide();
				});
			});
		</script>
		<script type="text/javascript" charset="utf-8">
			$.get('/tasks', function(data) {
				$('#tasks_div').html(data);
				ContactQuickShow.init();
			}, 'html');
			$("#context").val("tasks");
		</script>

	</div>
	</div>
</div>
	


</body></html>
